package com.cyclinggle.cloud.config;

import java.util.concurrent.TimeUnit;

import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import feign.Feign;
import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;

@Configuration
@ConditionalOnClass(Feign.class)
@AutoConfigureBefore(FeignAutoConfiguration.class)
public class OkHttpFeignConfig {
	
	@Bean
	public OkHttpClient okHttpClient() {
		return new OkHttpClient.Builder()
							   .connectTimeout(60, TimeUnit.SECONDS)	
							   .readTimeout(60, TimeUnit.SECONDS)
							   .writeTimeout(60, TimeUnit.SECONDS)
							   .retryOnConnectionFailure(true)
							   .connectionPool(new ConnectionPool())
							   .build();
	}

}
